﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.ComponentModel;

namespace yeqw.FrameWork
{
    public static class EnumExtensions
    {
        /// <summary>
        /// yyyy-MM-dd HH:mm:ss:fff
        /// </summary>
        /// <param name="input"></param>
        /// <param name="parrtern"></param>
        /// <returns></returns>
        public static string GetEnumCNNameFromEnum(this Enum enumval, Type enumType)
        {
            string enumvalue = Enum.GetName(enumType, enumval);
            if (enumvalue == string.Empty || enumvalue == null)
                return "";
            FieldInfo finfo = enumType.GetField(enumvalue);
            object[] cAttr = finfo.GetCustomAttributes(typeof(DescriptionAttribute), true);
            if (cAttr.Length > 0)
            {
                DescriptionAttribute desc = cAttr[0] as DescriptionAttribute;
                if (desc != null)
                {
                    return desc.Description;
                }
            }
            return enumvalue;
        }
    }
}
